有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javax的java替代位置。Windows中的comm.properties

我正在构建一个需要安装在Windows计算机上的程序,对于这些计算机,我没有对%JAVA\u HOME%/lib的写入权限

还有其他地方可以移动javax吗。是否将comm.properties指向%JAVA\u HOME%/lib以外的其他对象

根据Java COM API常见问题解答:

Q: My application does not find any ports when it enumerates available ports.
A: In order for the Java communications API to find ports the file javax.comm.properties must be in the correct place. The preferred location is in /lib. See the installation instructions for alternate locations and further information.

在哪里可以找到包含这些备用位置的Sun安装说明


共 (2) 个答案

  1. # 1 楼答案

    我找到了一种适合我的方法。以下是要求:

    • comm.jar必须精确命名为comm.jar(例如,不是comm-2.0.jar),并且必须位于名为"lib"的目录中的类路径中
    • javax.comm.properties也必须具有该确切名称,并且位于与comm.jar相同的目录中
    • win32com.dll必须在java.library.path中引用

    因此,如果您有如下目录设置:

    - lib\
       |- comm.jar
       |- javax.comm.properties
    - ext\
       |- win32com.dll
    

    然后,您可以在这些目录的根目录中使用以下java命令(假设项目的jar文件和YourMainClass也在lib目录中:

    java -Djava.library.path=.\ext -cp .\lib\* YourMainClass
    

    这样,您就不再需要在JRE的\bin\lib目录下放置任何内容

  2. # 2 楼答案

    根据一个家伙说的话: https://forums.oracle.com/forums/thread.jspa?threadID=1316406

    您可以将文件放入javax。comm.properties您放置comm.jar的位置。但要运行该程序,您应该指定指向comm.jar的路径,如下所示:

    java -cp <your.class.path>;<path.to>/comm.jar YourProgramThatUsesComm.jar
    

    希望有帮助